﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using brockredge.CLASSES;
using AjaxControlToolkit;


namespace brockredge
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var qstr = Request.QueryString["u"];
            if (qstr == null)
            {
                DisplayAllAdd();
            }
            else
            {
                DisplayAddByLocation(qstr.ToString());
            }
            
            //DropDownList ddlcity = (DropDownList)Master.FindControl("ddlStMain");
            //ddlcity.Attributes.Add("OnChange","displayAddbyLocation(this)");  
           
        }

       
        public void DisplayAddByLocation(string licid)
        {
            //ActivitiesDataContext adc = new ActivitiesDataContext();
            //var addvertisementQ = from add in adc.Advertisements
            //                      where add.lic_id == (Guid)licid.ToGuid()
            //                      orderby add.createDate descending
            //                      select add;

            //if (addvertisementQ.Count() > 0)
            //{
            //    mainAddContentRep.DataSource = addvertisementQ;
            //    mainAddContentRep.DataBind();
            //}

        }

        private void DisplayAllAdd()
        {
            testDataContext adc = new testDataContext();
            var addvertisementQ = from add in adc.Advertisements
                                  orderby add.createDate descending
                                  select add;

            if (addvertisementQ.Count() > 0)
            {
                mainAddContentRep.DataSource = addvertisementQ;
                mainAddContentRep.DataBind();
            }
        }

        protected void searchbtn_Click(object sender, EventArgs e)
        {
            if (ddlarea.Text == "")
                return;
            var sell = 0;
            var rent = 0;
            if (chkSell.Checked)
                sell = 1;
            if (chkRent.Checked)
                rent = 1;
            testDataContext tdc = new testDataContext();
            var advertisementQ = from add in tdc.Advertisements
                                 where tdc.Location_Cities.Any(lc => lc.city_id == (Guid)ddlcity.Text.ToGuid()
                                     && lc.location_id == add.Location_id && (add.IsForRent == rent || add.IsForSell == sell))
                                 select add;

            if (advertisementQ.Count() > 0)
            {
                //resultRep.DataSource = advertisementQ;
                //resultRep.DataBind();
            }

        }


       
    }

}